//
//  SAGoodsListCell.m
//  YunFu
//
//  Created by Bager on 2018/9/11.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "SAGoodsListCell.h"

@implementation SAGoodsListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setViews];
    }
    
    return self;
}

- (void)setViews
{
    [self addSubview:self.img];
    [self addSubview:self.name];
    [self addSubview:self.type];
    [self addSubview:self.tagView];
    [self addSubview:self.price];
    [self addSubview:self.address];
    [self addSubview:self.inBtn];
}

- (UIImageView *)img
{
    if (!_img)
    {
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(kPublicMargin, 5, 110, 120)];
        _img.contentMode = UIViewContentModeScaleAspectFill;
        _img.layer.masksToBounds = YES;
        _img.layer.cornerRadius = 4;
        [_img setImage:[UIImage imageNamed:@"yf2-mddh1-15"]];
    }
    return _img;
}

- (UILabel *)name
{
    if (!_name)
    {
        _name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.img.frame) + 10, 5, kScreenWidth - kPublicMargin - CGRectGetMaxX(self.img.frame) - 10, 36)];
        _name.font = [UIFont systemFontOfSize:14];
        _name.numberOfLines = 2;
        _name.text = @"外星人Alienware15.6英寸Gsync屏游戏笔记本电脑(i7-7700HQ 8G 256GSSD+1T GTX1050Ti 2G独显 FHD 酷炫灯效)";
    }
    return _name;
}

- (UILabel *)type
{
    if (!_type)
    {
        _type = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.name.frame), CGRectGetWidth(self.name.frame), 20)];
        _type.font = [UIFont systemFontOfSize:12];
        _type.textColor = [UIColor grayColor];
        _type.text = @"店铺券满3000减100";
    }
    return _type;
}

- (UIView *)tagView
{
    if (!_tagView)
    {
        _tagView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.type.frame) + 5, CGRectGetWidth(self.type.frame), 20)];
        
        [self.tagViewUtils tagLabelOnClick:^(UITapGestureRecognizer *tapGes, UILabel *tagLabel) {
            
        }];
        [self.tagViewUtils setupCommonTagsInView:_tagView tagTexts:@[@"包邮",@"只换不修"] margin:4 tagHeight:16];
        _tagViewUtils.commonTagStyle = ZYHTCommonTagStyleNormalBlueTag;
    }
    return _tagView;
}

- (LLTagViewUtils *)tagViewUtils
{
    if (!_tagViewUtils)
    {
        _tagViewUtils = [LLTagViewUtils new];
    }
    return _tagViewUtils;
}

- (UILabel *)price
{
    if (!_price)
    {
        _price = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.tagView.frame) + 5, CGRectGetWidth(self.name.frame), 20)];
        _price.font = [UIFont systemFontOfSize:10];
        _price.textColor = [UIColor lightGrayColor];
        _price.adjustsFontSizeToFitWidth = YES;
        _price.text = @"¥ 4888 12万人付款";
        _price.attributedText = [self convertColorString:_price.text];
    }
    return _price;
}

- (NSMutableAttributedString *)convertColorString:(NSString *)str
{
    NSMutableAttributedString *strnew = [[NSMutableAttributedString alloc]initWithString:str];
    [strnew addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 6)];
    [strnew addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0, 6)];
    return strnew;
}

- (UILabel *)address
{
    if (!_address)
    {
        _address = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.price.frame), CGRectGetWidth(self.name.frame), 20)];
        _address.font = [UIFont systemFontOfSize:10];
        _address.textColor = [UIColor lightGrayColor];
        _address.adjustsFontSizeToFitWidth = YES;
        _address.text = @"荣耀旗舰店 广州";
    }
    return _address;
}

- (UIButton *)inBtn
{
    if (!_inBtn)
    {
        _inBtn = [[UIButton alloc] init];
        [_inBtn setFrame:CGRectMake(kScreenWidth - kPublicMargin - 44, CGRectGetMaxY(self.price.frame), 44, 20)];
        [_inBtn setTitle:@"进店 >" forState:UIControlStateNormal];
        _inBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_inBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }
    return _inBtn;
}


@end
